using System;
using MSSystem = System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;
using Toenda.Rails.Data;
using Toenda.Rails.DataContainer;

namespace Toenda.Rails {
	namespace System {
		/// <summary>
		/// Class ImageProvider
		/// </summary>
		public sealed class ImageProvider {
			// ---------------------------------------------------------
			// CONSTRUCTORS
			// ---------------------------------------------------------

			/// <summary>
			/// Default Constructor
			/// </summary>
			public ImageProvider() {
			}

			// ---------------------------------------------------------
			// PUBLIC MEMBERS
			// ---------------------------------------------------------

			/// <summary>
			/// Get a list of the newest images
			/// </summary>
			/// <returns></returns>
			public ArrayList GetNewestImageList() {
				DBImage db = new DBImage();
				return db.GetNewestImageList(0);
			}

			/// <summary>
			/// get a list of the newest images
			/// </summary>
			/// <param name="Amount">The amount of images</param>
			/// <returns></returns>
			public ArrayList GetNewestImageList(int Amount) {
				DBImage db = new DBImage();
				return db.GetNewestImageList(Amount);
			}

			/// <summary>
			/// Get a list of all images
			/// </summary>
			/// <returns>A list of all images</returns>
			public List<ImageItem> GetImageList() {
				DBImage db = new DBImage();
				return db.GetImageList(0, 0, 0, false);
			}

			/// <summary>
			/// Get a list of all favorite images
			/// </summary>
			/// <param name="start">A amount of items (if end 0 = get all).</param>
			/// <param name="end">end</param>
			/// <param name="valuesperpage">valuesperpage</param>
			/// <param name="withuser"></param>
			/// <returns>A list of all images</returns>
			public List<ImageItem> GetFavoritesList(string userid, int start, int end, int valuesperpage, bool withuser) {
				DBImage db = new DBImage();
				return db.GetFavoritesList(userid, start, end, valuesperpage, withuser);
			}

			/// <summary>
			/// Get a list of all images
			/// </summary>
			/// <param name="start">A amount of items (if end 0 = get all).</param>
			/// <param name="end">end</param>
			/// <param name="valuesperpage">valuesperpage</param>
			/// <param name="withuser"></param>
			/// <returns>A list of all images</returns>
			public List<ImageItem> GetImageList(int start, int end, int valuesperpage, bool withuser) {
				DBImage db = new DBImage();
				return db.GetImageList(start, end, valuesperpage, withuser);
			}

			/// <summary>
			/// Get a list of all images related to a user.
			/// </summary>
			/// <param name="UserID">The ID of a user.</param>
			/// <exception cref="ArgumentNullException">If UserID is null.</exception>
			/// <returns>A ArrayList of all images</returns>
			public ArrayList GetImageList(string UserID) {
				if(UserID == null) {
					throw new ArgumentNullException("UserID");
				}

				DBImage db = new DBImage();
				return db.GetImageList(UserID, 0, 0, 0);
			}

			/// <summary>
			/// Get a list of all images related to a user.
			/// </summary>
			/// <param name="UserID">The ID of a user.</param>
			/// <param name="start">A amount of items (if end 0 = get all).</param>
			/// <param name="end">end</param>
			/// <param name="valuesperpage">valuesperpage</param>
			/// <exception cref="ArgumentNullException">If UserID is null.</exception>
			/// <returns>A ArrayList of all images</returns>
			public ArrayList GetImageList(string UserID, int start, int end, int valuesperpage) {
				if(UserID == null) {
					throw new ArgumentNullException("UserID");
				}

				DBImage db = new DBImage();
				return db.GetImageList(UserID, start, end, valuesperpage);
			}

			/// <summary>
			/// Get a list of all images related to a user.
			/// </summary>
			/// <param name="UserID">The ID of a user.</param>
			/// <param name="start">A amount of items (if end 0 = get all).</param>
			/// <param name="end">end</param>
			/// <param name="valuesperpage">valuesperpage</param>
			/// <param name="aslist"></param>
			/// <exception cref="ArgumentNullException">If UserID is null.</exception>
			/// <returns>A ArrayList of all images</returns>
			public List<ImageItem> GetImageList(string UserID, int start, int end, int valuesperpage, bool aslist, bool isLoggedIn) {
				if(UserID == null) {
					throw new ArgumentNullException("UserID");
				}

				DBImage db = new DBImage();
				return db.GetImageList(UserID, start, end, valuesperpage, aslist, isLoggedIn);
			}

			/// <summary>
			/// Get a list of all images related to a user.
			/// </summary>
			/// <param name="userID">The ID of a user.</param>
			/// <param name="currentUser">The current user.</param>
			/// <param name="start">A amount of items (if end 0 = get all).</param>
			/// <param name="end">end</param>
			/// <param name="valuesperpage">valuesperpage</param>
			/// <exception cref="ArgumentNullException">If UserID is null.</exception>
			/// <returns>A ArrayList of all images</returns>
			public List<ImageItem> GetImageListForImageBar(string userID, Account currentUser, int start, int end, int valuesperpage) {
				if(userID == null) {
					throw new ArgumentNullException("userID");
				}

				DBImage db = new DBImage();
				return db.GetImageListForImageBar(userID, currentUser, start, end, valuesperpage);
			}

			/// <summary>
			/// Get a list of all comments related to a image.
			/// </summary>
			/// <param name="ID">The ID of a image.</param>
			/// <exception cref="ArgumentNullException">If ID is null.</exception>
			/// <returns>A ArrayList of all comments</returns>
			public ArrayList GetImageCommentList(string ID) {
				if(ID == null)
					throw new ArgumentNullException("ID");

				DBImage db = new DBImage();
				return db.GetImageCommentList(ID);
			}

			/// <summary>
			/// Get the amount of image
			/// </summary>
			/// <returns>A amount of all images</returns>
			public int GetImageAmount() {
				DBImage db = new DBImage();
				return db.GetImageAmount();
			}

			/// <summary>
			/// Get the amount of images related to a user
			/// </summary>
			/// <param name="UserID">The ID of a user.</param>
			/// <param name="word"></param>
			/// <exception cref="ArgumentNullException">If UserID is null.</exception>
			/// <returns>A ArrayList of all images</returns>
			public BadgeSettings GetBadgeSetting(string UserID) {
				if(UserID == null)
					throw new ArgumentNullException("UserID");

				DBImage db = new DBImage();
				return db.GetBadgeSettings(UserID);
			}

			/// <summary>
			/// Get the amount of images related to a user
			/// </summary>
			/// <param name="UserID">The ID of a user.</param>
			/// <param name="word"></param>
			/// <exception cref="ArgumentNullException">If UserID is null.</exception>
			/// <returns>A ArrayList of all images</returns>
			public int GetImageAmount(string UserID) {
				if(UserID == null)
					throw new ArgumentNullException("UserID");

				DBImage db = new DBImage();
				return db.GetImageAmount(UserID);
			}

			/// <summary>
			/// Get the amount of images related to a user
			/// </summary>
			/// <param name="UserID">The ID of a user.</param>
			/// <param name="word"></param>
			/// <exception cref="ArgumentNullException">If UserID is null.</exception>
			/// <returns>A ArrayList of all images</returns>
			public int GetImageAmount(string UserID, int type, string word) {
				if(UserID == null)
					throw new ArgumentNullException("UserID");

				DBImage db = new DBImage();
				return db.GetImageAmount(UserID, type, word);
			}

			/// <summary>
			/// Get the amount of all images of a user.
			/// </summary>
			/// <param name="word">The ID of a user or the search word.</param>
			/// <exception cref="ArgumentNullException">If word is null.</exception>
			/// <returns>The amount of all images of a user</returns>
			public int GetImageAmount(string word, int type, bool onlypublic) {
				if(word == null)
					throw new ArgumentNullException("word");

				DBImage db = new DBImage();
				return db.GetImageAmount(word, type, onlypublic);
			}

			/// <summary>
			/// Get the amount of all favorite images of a user.
			/// </summary>
			/// <param name="word">The ID of a user or the search word.</param>
			/// <param name="onlypublic"></param>
			/// <exception cref="ArgumentNullException">If word is null.</exception>
			/// <returns>The amount of all images of a user</returns>
			public int GetFavoriteImageAmount(string userid) {
				if(userid == null) {
					throw new ArgumentNullException("userid");
				}

				DBImage db = new DBImage();
				return db.GetFavoriteImageAmount(userid);
			}

			/// <summary>
			/// Get the amount of all sets of a user.
			/// </summary>
			/// <param name="word">The ID of a user.</param>
			/// <exception cref="ArgumentNullException">If id or userid is null.</exception>
			/// <returns>The amount of all sets of a user</returns>
			public int GetSetAmount(string id, string userid) {
				if(id == null) {
					throw new ArgumentNullException("id");
				}

				if(userid == null) {
					throw new ArgumentNullException("userid");
				}

				DBImage db = new DBImage();
				return db.GetSetAmount(id, userid);
			}

			/// <summary>
			/// Get the amount of all sets of a user.
			/// </summary>
			/// <param name="word">The ID of a user.</param>
			/// <exception cref="ArgumentNullException">If id or userid is null.</exception>
			/// <returns>The amount of all sets of a user</returns>
			public int GetSetAmount(string id, string userid, bool isloggedin) {
				if(id == null) {
					throw new ArgumentNullException("id");
				}

				if(userid == null) {
					throw new ArgumentNullException("userid");
				}

				DBImage db = new DBImage();
				return db.GetSetAmount(id, userid, isloggedin);
			}

			/// <summary>
			/// Get the amount of all views of a image.
			/// </summary>
			/// <param name="ImageID">The ID of a image.</param>
			/// <exception cref="ArgumentNullException">If ImageID is null.</exception>
			/// <returns>The amount of all views of a image</returns>
			public long GetImageViewAmount(string ImageID) {
				if(ImageID == null)
					throw new ArgumentNullException("ImageID");

				DBImage db = new DBImage();
				return db.GetImageViewAmount(ImageID);
			}

			/// <summary>
			/// Get the amount of all views from a user.
			/// </summary>
			/// <param name="UserID">The ID of the user.</param>
			/// <exception cref="ArgumentNullException">If UserID is null.</exception>
			/// <returns></returns>
			public long GetUserViewAmount(string UserID) {
				if(UserID == null)
					throw new ArgumentNullException("UserID");

				DBImage db = new DBImage();
				return db.GetUserViewAmount(UserID);
			}

			/// <summary>
			/// Get the amount of all comments of a image.
			/// </summary>
			/// <param name="ImageID">The ID of the image (guid).</param>
			/// <exception cref="ArgumentNullException">If ImageID is null.</exception>
			/// <returns>The amount of all images of a user</returns>
			public int GetImageCommentAmount(string ImageID) {
				if(ImageID == null)
					throw new ArgumentNullException("ImageID");

				DBImage db = new DBImage();
				return db.GetImageCommentAmount(ImageID);
			}

			/// <summary>
			/// Save a image item
			/// </summary>
			/// <param name="item">The image item</param>
			/// <exception cref="ArgumentNullException">If item is null.</exception>
			public void SaveImage(ImageItem item) {
				if(item == null)
					throw new ArgumentNullException("item");

				DBImage db = new DBImage();
				db.SaveImage(item);
			}

			/// <summary>
			/// Save a set item
			/// </summary>
			/// <param name="set">The set item</param>
			/// <exception cref="ArgumentNullException">If set is null.</exception>
			public void SaveSet(SetItem set) {
				if(set == null) {
					throw new ArgumentNullException("set");
				}

				DBImage db = new DBImage();
				db.SaveSet(set);
			}

			/// <summary>
			/// Save a set item
			/// </summary>
			/// <param name="set">The set item</param>
			/// <param name="getback"></param>
			/// <exception cref="ArgumentNullException">If set is null.</exception>
			public SetItem SaveSet(SetItem set, bool getback) {
				if(set == null) {
					throw new ArgumentNullException("set");
				}

				DBImage db = new DBImage();
				return db.SaveSet(set, getback);
			}

			/// <summary>
			/// Get a image item
			/// </summary>
			/// <param name="id">The id of a image as string.</param>
			/// <exception cref="ArgumentNullException">If id is null.</exception>
			/// <returns>A image</returns>
			public ImageItem GetImageByImageID(string id) {
				if(id == null) {
					throw new ArgumentNullException("id");
				}

				DBImage db = new DBImage();
				return db.GetImageByImageID(id);
			}

			/// <summary>
			/// Get a image item
			/// </summary>
			/// <param name="pkid">The pkid of a image as string.</param>
			/// <exception cref="ArgumentNullException">If pkid is null.</exception>
			/// <returns>A image</returns>
			public ImageItem GetImageByUniqueID(string pkid) {
				if(pkid == null) {
					throw new ArgumentNullException("pkid");
				}

				DBImage db = new DBImage();
				return db.GetImageByUniqueID(pkid);
			}

			/// <summary>
			/// Get a image item
			/// </summary>
			/// <param name="SmallImageID">The integer ID of a image as string.</param>
			/// <exception cref="ArgumentNullException">If ImageID is null.</exception>
			/// <returns>A image</returns>
			public ImageItem GetImage(string SmallImageID) {
				if(SmallImageID == null) {
					throw new ArgumentNullException("SmallImageID");
				}

				DBImage db = new DBImage();
				return db.GetImage(SmallImageID);
			}

			/// <summary>
			/// Get a image item
			/// </summary>
			/// <param name="SmallImageID">The integer ID of a image as long.</param>
			/// <returns>A image</returns>
			public ImageItem GetImage(long SmallImageID) {
				DBImage db = new DBImage();
				return db.GetImage(SmallImageID);
			}

			/// <summary>
			/// Get a set item
			/// </summary>
			/// <param name="id">The integer ID of a set as string.</param>
			/// <exception cref="ArgumentNullException">If id is null.</exception>
			/// <returns>A set</returns>
			public SetItem GetSet(string id) {
				if(id == null)
					throw new ArgumentNullException("id");

				DBImage db = new DBImage();
				return db.GetSet(id);
			}

			/// <summary>
			/// Get a set item
			/// </summary>
			/// <param name="id">The integer ID of a set as long.</param>
			/// <returns>A set</returns>
			public SetItem GetSet(long id) {
				DBImage db = new DBImage();
				return db.GetSet(id);
			}

			/// <summary>
			/// Get a set item
			/// </summary>
			/// <param name="id">The integer ID of a set as string.</param>
			/// <param name="withimages">If you want to get a set with the images inside, type true</param>
			/// <exception cref="ArgumentNullException">If id is null.</exception>
			/// <returns>A set</returns>
			public SetItem GetSet(string id, bool withimages) {
				if(id == null)
					throw new ArgumentNullException("id");

				DBImage db = new DBImage();
				return db.GetSet(id, withimages);
			}

			/// <summary>
			/// Get a set item
			/// </summary>
			/// <param name="id">The integer ID of a set as long.</param>
			/// <param name="withimages">If you want to get a set with the images inside, type true</param>
			/// <returns>A set</returns>
			public SetItem GetSet(long id, bool withimages) {
				DBImage db = new DBImage();
				return db.GetSet(id, withimages);
			}

			/// <summary>
			/// Get a set item
			/// </summary>
			/// <param name="pkid">The pkid of a set as string.</param>
			/// <exception cref="ArgumentNullException">If pkid is null.</exception>
			/// <returns>A set</returns>
			public SetItem GetSetByUniqueID(string pkid) {
				DBImage db = new DBImage();
				return db.GetSetByUniqueID(pkid);
			}

			/// <summary>
			/// Delete a image
			/// </summary>
			/// <param name="ImageID">The id of the image.</param>
			/// <exception cref="ArgumentNullException">If ImageID is null.</exception>
			public void DeleteImage(string ImageID) {
				if(ImageID == null)
					throw new ArgumentNullException("ImageID");

				DBImage db = new DBImage();
				db.DeleteImage(ImageID);
			}

			/// <summary>
			/// Delete a set
			/// </summary>
			/// <param name="ImageID">The id of the set.</param>
			/// <exception cref="ArgumentNullException">If id is null.</exception>
			public void DeleteSet(string id) {
				if(id == null)
					throw new ArgumentNullException("id");

				DBImage db = new DBImage();
				db.DeleteSet(id);
			}

			/// <summary>
			/// Delete a favorite from a image
			/// </summary>
			/// <param name="userid"></param>
			/// <param name="imageid">The id of the image.</param>
			/// <exception cref="ArgumentNullException">If userid or imageid is null.</exception>
			public void DeleteFavorite(string userid, string imageid) {
				if(userid == null) {
					throw new ArgumentNullException("userid");
				}

				if(imageid == null) {
					throw new ArgumentNullException("imageid");
				}

				DBImage db = new DBImage();
				db.DeleteFavorite(userid, imageid);
			}

			/// <summary>
			/// Delete a image from a set
			/// </summary>
			/// <param name="imageid">The id of the image.</param>
			/// <param name="setid">The id of the set.</param>
			/// <exception cref="ArgumentNullException">If imageid or setid is null.</exception>
			public void DeleteImageFromSet(string imageid, string setid) {
				if(imageid == null) {
					throw new ArgumentNullException("imageid");
				}

				if(setid == null) {
					throw new ArgumentNullException("setid");
				}

				DBImage db = new DBImage();
				db.DeleteImageFromSet(imageid, setid);
			}

			/// <summary>
			/// Save a comment item
			/// </summary>
			/// <param name="item">The comment item</param>
			/// <exception cref="ArgumentNullException">If commentitem is null.</exception>
			public void SaveComment(CommentItem item) {
				if(item == null)
					throw new ArgumentNullException("item");

				DBImage db = new DBImage();
				db.SaveComment(item);
			}

			/// <summary>
			/// Save a favorite image
			/// </summary>
			/// <param name="userid"></param>
			/// <param name="imageid"></param>
			/// <exception cref="ArgumentNullException">If userid or imageid is null.</exception>
			public void SaveFavoriteImage(string userid, string imageid) {
				if(userid == null) {
					throw new ArgumentNullException("userid");
				}

				if(imageid == null) {
					throw new ArgumentNullException("imageid");
				}

				DBImage db = new DBImage();
				db.SaveFavoriteImage(userid, imageid);
			}

			/// <summary>
			/// Get a imagelist by cam
			/// </summary>
			/// <param name="cam"></param>
			/// <param name="start"></param>
			/// <param name="end"></param>
			/// <param name="userid"></param>
			/// <param name="valuesperpage"></param>
			/// <returns></returns>
			public List<ImageItem> GetImageListByCam(string cam, int type, int start, int end, string userid, int valuesperpage, bool isLoggedIn) {
				if(cam == null)
					throw new ArgumentNullException("cam");

				DBImage db = new DBImage();
				return db.GetImageListByCam(cam, type, start, end, userid, valuesperpage, isLoggedIn);
			}

			/// <summary>
			/// Get a imagelist by cam
			/// </summary>
			/// <param name="cam"></param>
			/// <param name="type"></param>
			/// <param name="start"></param>
			/// <param name="end"></param>
			/// <returns></returns>
			public List<ImageItem> GetImageListByCam(string cam, int type, int start, int end, bool isLoggedIn) {
				if(cam == null)
					throw new ArgumentNullException("cam");

				DBImage db = new DBImage();
				return db.GetImageListByCam(cam, type, start, end, isLoggedIn);
			}

			/// <summary>
			/// Get a imagelist by cam
			/// </summary>
			/// <param name="cam"></param>
			/// <param name="type"></param>
			/// <param name="start"></param>
			/// <param name="end"></param>
			/// <param name="userid"></param>
			/// <returns></returns>
			public List<ImageItem> GetImageListByCam(string cam, int type, int start, int end, string userID, bool isLoggedIn) {
				if(cam == null)
					throw new ArgumentNullException("cam");

				DBImage db = new DBImage();
				return db.GetImageListByCam(cam, type, start, end, userID, 0, isLoggedIn);
			}

			/// <summary>
			/// Get a imagelist by tag
			/// </summary>
			/// <param name="tag"></param>
			/// <param name="type"></param>
			/// <param name="start"></param>
			/// <param name="end"></param>
			/// <param name="userid"></param>
			/// <param name="valuesperpage"></param>
			/// <returns></returns>
			public List<ImageItem> GetImageListByTag(string tag, int type, int start, int end, string userID, int valuesPerPage) {
				if(tag == null)
					throw new ArgumentNullException("tag");

				DBImage db = new DBImage();
				return db.GetImageListByTag(tag, type, start, end, userID, valuesPerPage);
			}

			/// <summary>
			/// Get a imagelist by tag
			/// </summary>
			/// <param name="tag"></param>
			/// <param name="type"></param>
			/// <param name="start"></param>
			/// <param name="end"></param>
			/// <returns></returns>
			public List<ImageItem> GetImageListByTag(string tag, int type, int start, int end) {
				if(tag == null)
					throw new ArgumentNullException("tag");

				DBImage db = new DBImage();
				return db.GetImageListByTag(tag, type, start, end);
			}

			/// <summary>
			/// Get a imagelist by tag
			/// </summary>
			/// <param name="tag"></param>
			/// <param name="type"></param>
			/// <param name="start"></param>
			/// <param name="end"></param>
			/// <param name="userid"></param>
			/// <returns></returns>
			public List<ImageItem> GetImageListByTag(string tag, int type, int start, int end, string userid) {
				if(tag == null)
					throw new ArgumentNullException("tag");

				DBImage db = new DBImage();
				return db.GetImageListByTag(tag, type, start, end, userid, 0);
			}

			/// <summary>
			/// Get a imagelist ba params
			/// </summary>
			/// <param name="word"></param>
			/// <param name="type"></param>
			/// <param name="start"></param>
			/// <param name="end"></param>
			/// <returns></returns>
			public ArrayList GetImageListByParam(string word, int type, int start, int end) {
				if(word == null)
					throw new ArgumentNullException("word");

				DBImage db = new DBImage();
				return db.GetImageListByParam(word, type, start, end);
			}

			/// <summary>
			/// Get a imagelist ba params
			/// </summary>
			/// <param name="word"></param>
			/// <param name="amount"></param>
			/// <param name="userid"></param>
			/// <returns></returns>
			public ArrayList GetImageListByParam(string word, int type, int start, int end, string userid) {
				if(word == null)
					throw new ArgumentNullException("word");

				DBImage db = new DBImage();
				return db.GetImageListByParam(word, type, start, end, userid);
			}

			/// <summary>
			/// Get a random image item
			/// </summary>
			/// <returns></returns>
			public ImageItem GetRandomImage() {
				DBImage db = new DBImage();
				return db.GetRandomImage();
			}

			/// <summary>
			/// Get a list of all tags with its popularity
			/// </summary>
			/// <returns></returns>
			public ArrayList GetTagPopularityList() {
				DBImage db = new DBImage();
				return db.GetTagPopularityList();
			}

			/// <summary>
			/// Get a list of sets. This methods loads the images.
			/// </summary>
			/// <param name="id"></param>
			/// <param name="withimages"></param>
			/// <returns></returns>
			public List<SetItem> GetUserSets(string id) {
				DBImage db = new DBImage();
				return db.GetUserSets(id, true);
			}

			/// <summary>
			/// Get a list of sets. The parameter "withimages" decide if the images should load.
			/// </summary>
			/// <param name="id"></param>
			/// <param name="withimages"></param>
			/// <returns></returns>
			public List<SetItem> GetUserSets(string id, bool withimages) {
				DBImage db = new DBImage();
				return db.GetUserSets(id, withimages);
			}

			/// <summary>
			/// Check if a image is set to a image-set
			/// </summary>
			/// <param name="id">The id of the image</param>
			/// <returns></returns>
			/// <exception cref="ArgumentNullException">If id is null.</exception>
			public bool ImageHasSet(string id) {
				if(id == null) {
					throw new ArgumentNullException(
						"id",
						"The parameter id cannot be null!"
					);
				}

				DBImage db = new DBImage();
				return db.ImageHasSet(id);
			}

			/// <summary>
			/// Check if a image is a favorite image of a user
			/// </summary>
			/// <param name="userid"></param>
			/// <param name="imageid"></param>
			/// <returns></returns>
			/// <exception cref="ArgumentNullException">If userid or imageid is null.</exception>
			public bool ImageIsFavorite(string userid, string imageid) {
				if(userid == null) {
					throw new ArgumentNullException("userid");
				}

				if(imageid == null) {
					throw new ArgumentNullException("imageid");
				}

				DBImage db = new DBImage();
				return db.ImageIsFavorite(userid, imageid);
			}

			/// <summary>
			/// Get the amount of sets related to a user.
			/// </summary>
			/// <param name="id"></param>
			/// <returns></returns>
			public int GetUserSetsAmount(string id) {
				DBImage db = new DBImage();
				return db.GetUserSetsAmount(id);
			}

			/// <summary>
			/// Add a image to a set
			/// </summary>
			/// <param name="imageid"></param>
			/// <param name="setid"></param>
			public void AddImageToSet(string imageid, string setid) {
				DBImage db = new DBImage();
				db.AddImageToSet(imageid, setid);
			}

			/// <summary>
			/// Get all sets for an image
			/// </summary>
			/// <param name="imageid"></param>
			/// <returns></returns>
			public List<SetItem> GetSetsByImageID(string imageid) {
				DBImage db = new DBImage();
				return db.GetSetsByImageID(imageid);
			}

			/// <summary>
			/// Check if a set exists
			/// </summary>
			/// <param name="ImageID">The ID of a set.</param>
			/// <exception cref="ArgumentNullException">If setid is null.</exception>
			/// <returns></returns>
			public bool CheckSetExists(string setid) {
				if(setid == null) {
					throw new ArgumentNullException("setid");
				}

				DBImage db = new DBImage();
				return db.CheckSetExists(setid);
			}

			/// <summary>
			/// Check if a image exists
			/// </summary>
			/// <param name="ImageID">The ID of a image.</param>
			/// <exception cref="ArgumentNullException">If imageid is null.</exception>
			/// <returns></returns>
			public bool CheckImageExists(string imageid) {
				if(imageid == null) {
					throw new ArgumentNullException("imageid");
				}

				DBImage db = new DBImage();
				return db.CheckImageExists(imageid);
			}

			/// <summary>
			/// Count the amount of views of an image
			/// </summary>
			/// <param name="id">The ID of a image.</param>
			public void CountImageView(string id) {
				DBImage db = new DBImage();
				db.CountImageView(id);
			}

			/// <summary>
			/// Get the amount of all images of a tag.
			/// </summary>
			/// <param name="tag">The search tag.</param>
			/// <exception cref="ArgumentNullException">If tag is null.</exception>
			/// <returns>The amount of all images of a tag</returns>
			public int GetImageAmountByTag(string tag, int type) {
				if(tag == null) {
					throw new ArgumentNullException("tag");
				}

				DBImage db = new DBImage();
				return db.GetImageAmountByTag(tag, type);
			}

			/// <summary>
			/// Get the amount of all images of a tag.
			/// </summary>
			/// <param name="tag">The search tag.</param>
			/// <param name="userid">The user id</param>
			/// <exception cref="ArgumentNullException">If tag is null.</exception>
			/// <returns>The amount of all images of a tag</returns>
			public int GetImageAmountByTag(string userid, string tag, int type) {
				if(tag == null) {
					throw new ArgumentNullException("tag");
				}

				DBImage db = new DBImage();
				return db.GetImageAmountByTag(userid, tag, type);
			}

			/// <summary>
			/// Get the amount of all images of a cam.
			/// </summary>
			/// <param name="cam">The ID of a user or the search tag.</param>
			/// <param name="type"></param>
			/// <exception cref="ArgumentNullException">If cam is null.</exception>
			/// <returns>The amount of all images of a cam</returns>
			public int GetImageAmountByCam(string cam, int type, bool isLoggedIn) {
				if(cam == null) {
					throw new ArgumentNullException("cam");
				}

				DBImage db = new DBImage();
				return db.GetImageAmountByCam(cam, type, isLoggedIn);
			}

			/// <summary>
			/// Get the amount of all images of a cam.
			/// </summary>
			/// <param name="userID">The user id</param>
			/// <param name="cam">The search cam.</param>
			/// <param name="type"></param>
			/// <exception cref="ArgumentNullException">If cam is null.</exception>
			/// <returns>The amount of all images of a cam</returns>
			public int GetImageAmountByCam(string userID, string cam, int type, bool isLoggedIn) {
				if(userID == null) {
					throw new ArgumentNullException("userID");
				}

				if(cam == null) {
					throw new ArgumentNullException("cam");
				}

				DBImage db = new DBImage();
				return db.GetImageAmountByCam(userID, cam, type, isLoggedIn);
			}

			/// <summary>
			/// Get the amount of the mostly used tag
			/// </summary>
			/// <returns></returns>
			public int GetMostlyUsedTagAmount() {
				DBImage db = new DBImage();
				return db.GetMostlyUsedTagAmount();
			}

			/// <summary>
			/// Generate a badge setting
			/// </summary>
			/// <param name="bs"></param>
			/// <returns></returns>
			public string GenerateZapprBadge(BadgeSettings bs, string badgepath, string imagepath) {
				StringBuilder code = new StringBuilder();
				DBImage db_img = new DBImage();
				int count = 0;
				string imagewidth = "";
				string imageheight = "";
				string serverpath = badgepath;
				string path = imagepath;

				// save badge settings
				db_img.SaveBadgeSettings(bs);

				DirectoryInfo dir = new DirectoryInfo(serverpath + "\\" + bs.UserID);
				if(!dir.Exists)
					dir.Create();

				// generate css
				code.Append("\n");
				code.Append("/* Zappr Badge CSS Code */\n");
				code.Append("/* Copyright (c) Toenda Software Development */\n");
				code.Append("\n");

				if(bs.BadgeBorderStyle != ""
				&& bs.BadgeBorderStyle != "none") {
					code.Append("#zapprBadgeTable {");
					code.Append(" border:");
					code.Append(" " + bs.BadgeBorderWidth.ToString() + "px");
					code.Append(" " + bs.BadgeBorderStyle);
					code.Append(" #" + bs.BadgeBorderColor);
					code.Append(" !important; }\n");
				}

				code.Append("#zapprBadgeTable a:link,");
				code.Append(" #zapprBadgeTable a:hover,");
				code.Append(" #zapprBadgeTable a:active,");
				code.Append(" #zapprBadgeTable a:visited { text-decoration: none !important; background: inherit !important; }\n");
				code.Append("#zapprBadgeList {  }\n");
				code.Append("#zapprBadgeImage {  }\n");
				code.Append(".zapprBadgeImage {  }\n");

				if(bs.ImageBorderColor != "" 
				&& bs.ImageBorderStyle != "none") {
					code.Append(".zapprBadgeImage img {");
					code.Append(" border:");
					code.Append(" " + bs.ImageBorderWidth.ToString() + "px");
					code.Append(" " + bs.ImageBorderStyle);
					code.Append(" #" + bs.ImageBorderColor);
					code.Append(" !important; }\n");
				}

				code.Append("\n");

				/*
				#flickr_badge_source_txt {padding:0; font: 11px Arial, Helvetica, Sans serif; color:#666666;}
				#flickr_badge_icon {display:block !important; margin:0 !important; border: 1px solid rgb(0, 0, 0) !important;}
				#flickr_icon_td {padding:0 5px 0 0 !important;}
				.flickr_badge_image {text-align:center !important;}
				----.flickr_badge_image img {border: 1px solid black !important;}
				#flickr_www {display:block; padding:0 10px 0 10px !important; font: 11px Arial, Helvetica, Sans serif !important; color:#3993ff !important;}
				---#flickr_badge_uber_wrapper a:hover,
				---#flickr_badge_uber_wrapper a:link,
				---#flickr_badge_uber_wrapper a:active,
				---#flickr_badge_uber_wrapper a:visited {text-decoration:none !important; background:inherit !important;color:#3993ff;}
				---#flickr_badge_wrapper {}
				#flickr_badge_source {padding:0 !important; font: 11px Arial, Helvetica, Sans serif !important; color:#666666 !important;}
				*/

				StreamWriter sw1 = new StreamWriter(
					serverpath + "\\" + bs.UserID + "\\" + bs.CodeID + ".css",
					false
				);
				sw1.Write(code.ToString());
				sw1.Close();

				// generate code
				List<ImageItem> list = db_img.GetImageListForBadge(bs.UserID, 0, bs.ImageAmount);

				code.Remove(0, code.Length);
				code.Append("\n");
				code.Append("// Zappr Badge Javascript Code\n");
				code.Append("// Copyright (c) Toenda Software Development\n");
				code.Append("\n");
				code.Append("var image_list = '';\n");
				code.Append("\n");

				if(bs.BadgeVertical == false) {
					code.Append("image_list += '<tr>';");
				}

				foreach(ImageItem item in list) {
					//MSSystem.Drawing.Bitmap bmp = new MSSystem.Drawing.Bitmap(
					//	path + "\\Images\\" + item.Image75x75
					//);
					imagewidth = "75";// bmp.Size.Width.ToString();
					imageheight = "75";// bmp.Size.Height.ToString();

					if(bs.BadgeVertical) {
						code.Append("image_list += '<tr>");
					}
					else {
						code.Append("image_list += '");
					}

					code.Append("<td");
					code.Append(" align=\"center\"");
					code.Append(" valign=\"center\"");
					code.Append(" class=\"zapprBadgeImage\"");
					code.Append(" id=\"zapprBadgeImage" + count.ToString() + "\"");
					code.Append(">");
					
					//code.Append("<a href=\"http://www.zappr.net/default.aspx?item=");
					//code.Append(item.ImageID.ToString() + "\"");
					code.Append("<a href=\"http://www.zappr.net/photo/");
					code.Append(item.ImageID.ToString());
					code.Append("/default.aspx\"");

					code.Append(" target=\"_blank\">");
					code.Append("<img src=\"http://www.zappr.net/Images/" + item.Image75x75 + "\"");
					code.Append(" alt=\"" + item.Name.Replace("'", "`") + "\"");
					code.Append(" title=\"" + item.Name.Replace("'", "`") + "\"");
					code.Append(" width=\"" + imagewidth + "\"");
					code.Append(" height=\"" + imageheight + "\"");
					code.Append(" />");
					code.Append("</a>");
					code.Append("</td>");

					if(bs.BadgeVertical) {
						code.Append("</tr>';");
					}
					else {
						code.Append("';");
					}

					code.Append("\n");

					count++;
				}

				if(bs.BadgeVertical == false) {
					code.Append("image_list += '</tr>';");
				}

				code.Append("\n");
				code.Append("document.write(image_list);\n");
				code.Append("\n");

				StreamWriter sw2 = new StreamWriter(
					serverpath + "\\" + bs.UserID + "\\" + bs.CodeID + ".js",
					false
				);
				sw2.Write(code.ToString());
				sw2.Close();

				// generate badge
				code.Remove(0, code.Length);

				code.Append("<!-- Zappr Badge starts here -->\n");

				code.Append("<style type=\"text/css\">");
				code.Append("@import \"http://www.zappr.net/Badges/" + bs.UserID + "/" + bs.CodeID + ".css\";");
				code.Append("</style>\n");

				code.Append("<table id=\"zapprBadgeTable\" cellpadding=\"0\" cellspacing=\"10\"");
				code.Append(" border=\"0\">\n");
				code.Append("<tr><td>\n");

				if(bs.ZapprLinkPosition == 0) {
					code.Append("<div align=\"center\">");
					code.Append("<span style=\"font-size: 11px;\">");
					code.Append("<a style=\"text-decoration: none !important;\" ");
					code.Append("href=\"http://www.zappr.net\" target=\"_blank\"><strong>");
					code.Append("<span style=\"color:#222222;\">Zapp</span>");
					code.Append("<span style=\"color:#339933;\">r</span>");
					code.Append("</strong>");
					code.Append("</span>");
					code.Append("</div>\n");
				}

				// -->list start
				code.Append("<table id=\"zapprBadgeList\" cellpadding=\"0\" cellspacing=\"10\"");
				code.Append(" border=\"0\">\n");

				if(bs.ZapprLinkPosition == 2) {
					code.Append("<tr><td>");
					code.Append("<span style=\"font-size: 11px;\">");
					code.Append("<a style=\"text-decoration: none !important;\" ");
					code.Append("href=\"http://www.zappr.net\" target=\"_blank\"><strong>");
					code.Append("<span style=\"color:#222222;\">Zapp</span>");
					code.Append("<span style=\"color:#339933;\">r</span>");
					code.Append("</strong>");
					code.Append("</span>");
					code.Append("</td></tr>\n");
				}
				
				code.Append("<script type=\"text/javascript\" src=\"");
				code.Append("http://www.zappr.net/Badges/" + bs.UserID + "/" + bs.CodeID + ".js");
				code.Append("\"></script>\n");

				if(bs.ZapprLinkPosition == 3) {
					code.Append("<tr><td>");
					code.Append("<span style=\"font-size: 11px;\">");
					code.Append("<a style=\"text-decoration: none !important;\" ");
					code.Append("href=\"http://www.zappr.net\" target=\"_blank\"><strong>");
					code.Append("<span style=\"color:#222222;\">Zapp</span>");
					code.Append("<span style=\"color:#339933;\">r</span>");
					code.Append("</strong>");
					code.Append("</span>");
					code.Append("</td></tr>\n");
				}

				code.Append("</table>\n");
				// --> list end

				if(bs.ZapprLinkPosition == 1) {
					code.Append("<div align=\"center\">");
					code.Append("<span style=\"font-size: 11px;\">");
					code.Append("<a style=\"text-decoration: none !important;\" ");
					code.Append("href=\"http://www.zappr.net\" target=\"_blank\"><strong>");
					code.Append("<span style=\"color:#222222;\">Zapp</span>");
					code.Append("<span style=\"color:#339933;\">r</span>");
					code.Append("</strong>");
					code.Append("</a>");
					code.Append("</span>");
					code.Append("</div>\n");
				}

				code.Append("</td></tr>\n");
				code.Append("</table>\n");
				
				code.Append("<!-- Zappr Badge ends here -->\n");

				return code.ToString();
			}

			/// <summary>
			/// get a top ten list for the cameras
			/// </summary>
			/// <returns></returns>
			public List<Camera> GetTopTenCameraList() {
				DBImage db = new DBImage();
				return db.GetTopTenCameraList();
			}
		}
	}
}
